import { AppState } from "./../../store/index";
import { Selectors } from "src/app/store";
import { select } from "@ngrx/store";
import { Store } from "@ngrx/store";
import {
  ImgStoreData,
  initialEmptyConfig
} from "./../../../storage/.config/store.type";
import { Component, OnInit } from "@angular/core";
import { ActivatedRoute } from "@angular/router";

@Component({
  selector: "app-home",
  templateUrl: "./home.component.html",
  styleUrls: ["./home.component.scss"]
})
export class HomeComponent implements OnInit {
  constructor(private route: ActivatedRoute, private store$: Store<AppState>) {}

  keyword: string = "";
  storage: ImgStoreData = {
    config: initialEmptyConfig,
    data: []
  };

  ngOnInit() {
    this.route.data.subscribe(({ storage }) => {
      this.storage = storage;
    });

    this.store$.pipe(select(Selectors.keyword)).subscribe(({ keyword }) => {
      this.keyword = keyword;
    });
  }
}
